<?php
/*
 * @Created by: wangchengcheng
 * @Author: wangchengcheng
 * @Date: 2020-01-03 17:34:47
 * @LastEditors  : wangchengcheng
 * @LastEditTime : 2020-01-03 19:59:47
 */

namespace App\Models;

use Str;

/**
 * App\Models\Category
 *
 * @property                             int    $id 分类主键id
 * @property                             string $name 分类名称
 * @property                             string $slug slug
 * @property                             string $keywords 关键词
 * @property                             string $description 描述
 * @property                             int    $sort 排序
 * @property                             int    $pid 父级栏目id
 * @property \Illuminate\Support\Carbon|null    $created_at
 * @property \Illuminate\Support\Carbon|null    $updated_at
 * @property string|null $deleted_at
 */
class Category extends Base
{
    /**
     * 一对多关联文章
     */
    public function articles()
    {
        return $this->hasMany(Article::class);
    }

    public function getUrlAttribute()
    {
        $parameters = [$this->id];

        if(Str::isTrue(config('wblog.seo.use_slug'))){
            $parameters[] = $this->slug;
        }

        return url('category', $parameters);
    }
}
